package net.beyondts.example.mplug;

import net.beyondts.example.mplug.beans.SomeBean;
import net.beyondts.example.mplug.extension.SomeService;
import net.beyondts.mplug.utils.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Project: mplug-project<br/>
 * Description: <br/>
 * Created at: 2019-1-12<br/>
 * Owned by beyondts.
 *
 * @author blazecrystal
 * @version 1.0.0
 */
@SpringBootApplication(/*scanBasePackages = {"net.beyondts.example.mplug"}*/)
@RestController
@EnableAspectJAutoProxy
public class App {
//    @Bean
//    public ExtensionHandler createExtensionHandler() {
//        ExtensionHandler handler = new ExtensionHandler();
//        try {
//            PluginManager pm = new PluginManager("D:\\workspaces\\workspace-beyondts\\mplug-project\\extension-example" +
//                    "\\plugins");
//            handler.setPluginManager(pm);
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }
//        return handler;
//    }

    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
//        BeanFactory.initByApplicationContext(ac);
        System.out.println("start ok");
    }

    @Autowired
    private SomeService service;

    @Autowired
    private SomeBean b;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello() {
        service.print();
        service.print(10);
        b = (SomeBean) BeanFactory.getBean("someBean");
        System.out.println(b.getName() + "+++++++++++++");
        service.print("this is auto gen extension", 12);
//        System.out.println(service.test("this is in "));
        return "Hello Mplug";
    }
}
